package com.lsh.oms.provider.service.query;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.dubbo.rpc.protocol.rest.support.ContentType;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.lsh.base.common.model.CommonResult;
import com.lsh.oms.api.service.query.IFindBillConfigService;
import com.lsh.oms.core.constant.ReturnCode;
import com.lsh.oms.core.enums.OrderStatus;
import com.lsh.oms.core.service.query.ConfigBuilder;
import com.lsh.oms.core.service.tool.ToolService;
import com.lsh.oms.provider.service.BaseService;
import lombok.extern.slf4j.Slf4j;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

/**
 * Project Name: lsh-oms
 *
 * @author peter
 * @date 2020-01-16
 * 北京链商电子商务有限公司
 * Package
 * desc:
 */
@Service(protocol = "rest")
@Path("config/query")
@Consumes({MediaType.APPLICATION_FORM_URLENCODED, MediaType.MULTIPART_FORM_DATA, MediaType.APPLICATION_JSON})
@Produces({ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
@Slf4j
public class FindBillConfigServiceImpl  extends BaseService implements IFindBillConfigService {


    @GET
    @Path("order")
    @Override
    public String getOrderConfig() {
        log.info("Request order config : " + ToolService.getLogSign());
        CommonResult commonResult = new CommonResult();

        JSONObject configObject = new JSONObject();
        JSONObject orderStatusObject = new JSONObject(true);
        for (OrderStatus orderStatus : OrderStatus.values()) {
            orderStatusObject.put(String.valueOf(orderStatus.getIndex()), orderStatus.getName());
        }
        configObject.put("orderStatus", orderStatusObject);

        commonResult.setCode(ReturnCode.REQUEST_SUCCESS);
        commonResult.setMessage("success.");
        commonResult.setData(configObject);
        return JSON.toJSONString(commonResult, ToolService.valueFilter, SerializerFeature.WriteMapNullValue,
                SerializerFeature.WriteNullStringAsEmpty,
                SerializerFeature.WriteNullNumberAsZero);
    }

    @GET
    @Path("shipping")
    @Override
    public String getShippingConfig() {
        log.info("Request shipping config : " + ToolService.getLogSign());
        CommonResult commonResult = new CommonResult();
        commonResult.setCode(ReturnCode.REQUEST_SUCCESS);
        commonResult.setMessage("success.");
        commonResult.setData(ConfigBuilder.getConfigShipping());
        return JSON.toJSONString(commonResult, ToolService.valueFilter, SerializerFeature.WriteMapNullValue,
                SerializerFeature.WriteNullStringAsEmpty,
                SerializerFeature.WriteNullNumberAsZero);
    }

    @GET
    @Path("receipt")
    @Override
    public String getReceiptConfig() {
        log.info("Request receipt config : " + ToolService.getLogSign());
        CommonResult commonResult = new CommonResult();
        commonResult.setCode(ReturnCode.REQUEST_SUCCESS);
        commonResult.setMessage("success.");
        commonResult.setData(ConfigBuilder.getConfigReceipt());
        return JSON.toJSONString(commonResult, ToolService.valueFilter, SerializerFeature.WriteMapNullValue,
                SerializerFeature.WriteNullStringAsEmpty,
                SerializerFeature.WriteNullNumberAsZero);
    }


    @GET
    @Path("return")
    @Override
    public String getReturnConfig() {
        log.info("Request return config : " + ToolService.getLogSign());
        CommonResult commonResult = new CommonResult();
        commonResult.setCode(ReturnCode.REQUEST_SUCCESS);
        commonResult.setMessage("success.");
        commonResult.setData(ConfigBuilder.getConfigReturn());
        return JSON.toJSONString(commonResult, ToolService.valueFilter, SerializerFeature.WriteMapNullValue,
                SerializerFeature.WriteNullStringAsEmpty,
                SerializerFeature.WriteNullNumberAsZero);
    }
}
